<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157" text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <!--<div class="el-menu-search">
                <input size="mini" label="搜索" placeholder="请输入内容" v-model="s_rolecode" class="el-search-input" />
                <el-button slot="append" icon="el-icon-search" class="el-search-btn"> </el-button>
            </div>-->
            <template v-for="(item,i) in items">
                <template v-if="item.subs&&item.subs.length">
                    <el-submenu :index="item.index" :key="i">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from './bus';
    import { mapState } from 'vuex'
    export default {
        data() {
            return {
                s_rolecode: '',
                collapse: false,
                items: [{
                    icon: 'el-icon-tickets',
                    index: '1',
                    title: '退学处理',
					/* 配置左侧菜单路由 */
                    subs: [
                        {index: 'tollProject',title: '收费项目'},
                        {index: 'index',title: '支付管理'},
                        {index: 'payRecode',title: '退学处理'},
                        {index: 'packageManager',title: '套餐管理'}
                    ]
                }],
				/* 配置组件隐性路由 */
                menus: [
                    {index: 'paymentDetail',title: '支付详情'},
					{index: 'paycostDetail',title: '缴费详情'},
          {index: 'paycostEdit',title: '编辑缴费'},
                    {index: 'packageAdd',title: '添加套餐'},
                    {index: 'packageEdit',title: '编辑套餐'},
                    {index: 'packageDetail',title: '套餐详情'},
                    {index: 'vipUser',title: 'vip用户'},
                    {index: 'packageInfo',title: '套餐信息'},
                    {index: 'barCode',title: '条形码'},
                ]
            }
        },
        computed: mapState({
            menuList: state => state.menu.menuList,
            onRoutes() {
                return this.$route.path.replace('/', '');
            }
        }),
        created() {
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
        },
        mounted() {
            this.navInit();
        },
        methods: {
            navInit() {
                var self = this;
                var menuList = self.items[0].subs.concat(self.menus);
                self.$store.dispatch("add_Menus", menuList);
                self.$store.dispatch("add_Routes", menuList);
            }
        }
    }
</script>

<style lang="scss" scoped>
    .sidebar {
        display: block;
        position: absolute;
        left: 0;
        top: 55px;
        bottom: 0;
        overflow-y: auto;
        z-index: 120;
    }

    .sidebar::-webkit-scrollbar {
        width: 0;
    }

    .sidebar-el-menu:not(.el-menu--collapse) {
        width: 250px;
    }

    .sidebar>ul {
        height: 100%;
    }

    .sidebar .el-menu-search {
        height: 55px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar .el-menu-search .el-search-input {
        width: 170px;
        height: 30px;
        line-height: 36px;
        text-indent: 5px;
        color: #bfcbd9;
        outline: none;
        background-color: #4d688f;
        border: none;
        border-radius: 4px 0 0 4px;
    }

    .sidebar .el-menu-search .el-search-input::-webkit-input-placeholder {
        color: #999;
    }

    .sidebar .el-search-btn {
        width: 35px;
        height: 30px;
        padding: 5px;
        font-size: 16px;
        color: #bfcbd9;
        background-color: #4d688f;
        border: 1px solid #4d688f;
        border-radius: 0 4px 4px 0;
    }
</style>
